<html>
<body>
<kbd>Alt</kbd> is <span id="alt_state">no</span><br>
<kbd>Ctrl</kbd> is <span id="ctrl_state">no</span><br>
<kbd>Meta</kbd> is <span id="meta_state">no</span><br>
last keycode: <span id="last_keycode">none</span><br>

<script>

document.body.onkeydown = function(e) {
    if (e.altKey)
        alt_state.textContent = 'pressed'
    if (e.ctrlKey)
        ctrl_state.textContent = 'pressed'
    if (e.metaKey)
        meta_state.textContent = 'pressed'
    last_keycode.textContent = e.keyCode
    document.title = "Key pressed";
};
document.body.onkeyup = function(e) {
    if (e.altKey)
        alt_state.textContent = 'released'
    if (e.ctrlKey)
        ctrl_state.textContent = 'released'
    if (e.metaKey)
        meta_state.textContent = 'released'
    last_keycode.textContent = e.keyCode
    document.title = "Key released";
};

function getPressedModifiers() {
    return "alt:" + alt_state.textContent + " ctrl:" + ctrl_state.textContent + " meta:" + meta_state.textContent
}

</script>
</body>
</html>

